package cn.edu.nuc.ssm.dao;

import cn.edu.nuc.ssm.dto.EverySumCaiWuDto;
import cn.edu.nuc.ssm.entity.Account;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

public interface AccountMapper {
    @Delete({
        "delete from account",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into account (id, uid, ",
        "name, remain_money, ",
        "in_money, out_money, ",
        "date, accountType)",
        "values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, ",
        "#{name,jdbcType=VARCHAR}, #{remainMoney,jdbcType=DECIMAL}, ",
        "#{inMoney,jdbcType=DECIMAL}, #{outMoney,jdbcType=DECIMAL}, ",
        "#{date,jdbcType=CHAR}, #{accounttype,jdbcType=VARCHAR})"
    })
    int insert(Account record);

    int insertSelective(Account record);

    @Select({
        "select",
        "id, uid, name, remain_money, in_money, out_money, date, accountType",
        "from account",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("cn.edu.nuc.ssm.dao.AccountMapper.BaseResultMap")
    Account selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Account record);

    @Update({
        "update account",
        "set uid = #{uid,jdbcType=INTEGER},",
          "name = #{name,jdbcType=VARCHAR},",
          "remain_money = #{remainMoney,jdbcType=DECIMAL},",
          "in_money = #{inMoney,jdbcType=DECIMAL},",
          "out_money = #{outMoney,jdbcType=DECIMAL},",
          "date = #{date,jdbcType=CHAR},",
          "accountType = #{accounttype,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Account record);

    @Select({
        "select",
        "id, uid, name, remain_money, in_money, out_money, date, accountType",
         "from account",
         "limit #{start},#{offset}"
    })
    List<Account>  findPageList(@Param("start") int start,@Param("offset") int offset);

    List<Account> find();

    List<String> findaccounttype();


    List<Account> findbyUid(@Param("uid")Integer uid);

    /**
     * 统计用户的总资产
     * @param uid 用户id
     * @return 总资产
     */
    float sumZhichan(@Param("uid")Integer uid);

    /**
     * 统计一个用户的总债
     * @return 负债的总额
     */
    float sumFuzai(@Param("uid") int uid);

    /**
     * 按账户类型统计每一类账户的账务信息
     * @param uid
     * @return
     */
    List<EverySumCaiWuDto> everyAccontTypeSum(@Param("uid") int uid);

    /**
     *  更改账户的金钱数
     * @param id
     * @param remainMoney
     * @param inMoney
     * @param outMoney
     * @return
     */
    int modifyMoney(@Param("id") int id, @Param("remain_money") BigDecimal remainMoney, @Param("in_money")BigDecimal inMoney,@Param("out_money")BigDecimal outMoney);


    /**
     * 通过账户id和用户id查找一个账户的信息
     * @param id
     * @param uid
     * @return
     */
     Account findbyIdAnduid(@Param("id")Integer id,@Param("uid")Integer uid);

    /**
     * 通过账户id查找一个用户
     * @param id 账户的id
     * @return 要查找的账户信息
     */
    Account findbyId(@Param("id")Integer id);

    Account findbyUidAndname(@Param("uid")Integer uid,@Param("name")String name);


    int updateRemainMoneybyId(@Param("updatedRemainMoney")BigDecimal updatedRemainMoney,@Param("id")Integer id);




}